<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="__SKIN__/layui/css/layui.css" media="all">
    <script src="__JS__/jquery.js"></script>
    <script src="__SKIN__/layui/layui.all.js"></script>
    <script src="__SKIN__/layui/xm-select.js"></script>
    <!--CSS引用-->
    <link rel="stylesheet" href="__SKIN__/layui/css/layui.css" />
</head>
<body>
<div class="layui-body" style="left:20px;padding-right:20px;">
    <div class="layui-row">
    <!--发起流程 start-->
        <div>
            <div class="layui-form-item">
                <label class="layui-form-label">流程模版：</label>
                <div class="layui-input-block">
                    <div id="get_flowlist" style="width:200px;"></div>
                </div>
            </div>
        </div>
        <div>
            <form id="form" class="layui-form layui-form-pane" action="">

            </form>
        </div>
        <script src="__SKIN__/workflow/js/form_assembly.js" charset="utf-8"></script>
        <script>
            //同步ajax请求数据转出
            var ajax = function(url,data){
                var arr = {};
                $.ajax({
                    url:url,
                    type:'post',
                    data:data,
                    dataType:"html",
                    async: false,//关闭异步
                    success:function(e){
                        arr = eval('(' + e + ')');
                    }
                });
                return arr;
            }

            var form = layui.use('form', function(){
                var form = layui.form;


                xmSelect.render({
                    el:'#get_flowlist',
                    name:'get_flowlist',
                    radio: true,
                    tips: '请选择流程模版',
                    clickClose: true,
                    data: function(){
                        let  url = "{:url('Workflowajax/get_flowlist')}";
                        let  param = {};
                        let  data = ajax(url,param);
                        return data.data;
                    },
                    filterable: true,
                    on: function(data){
                        //change, 此次选择变化的数据,数组
                        let change = data.change;
                        let isAdd = data.isAdd;
                        $('#form').html('');
                        if(isAdd == false){
                            return false;
                        }

                        let urls = "{:url('Workflowajax/get_formconfig')}";
                        let arr = change[0].value;
                        let res= ajax(urls, {'flow_id':arr});
                        var html = '';
                            html+=loadhead(res.msg);
                        $.each(res.data,function(f,n){

                            switch (n.field_type) {
                                case 1:
                                    html += loadtext(n);
                                    break;
                                case 2:
                                    html += loadselect(n);
                                    break;
                                case 3:
                                    html += loadradio(n);
                                    break;
                                case 4:
                                    html += loadcheckbox(n);
                                    break;
                            }
                        });
                        //判断允许更改审核结构（审核人员，角色，部门）
                        html += loadbutton();

                        $('#form').html(html);
                        form.render();
                    },
                });

                //监听提交
                form.on('submit(form)', function(data){
                    let urlss = "{:url('Workflowajax/save_workflow')}";
                    ajax(urlss,JSON.stringify(data.field));
                    return false;
                });
                //各种基于事件的操作，下面会有进一步介绍
                form.render();
            });
        </script>
    <!--发起流程 end-->
    </div>
</div>
</body>
</html>